package com.gluck.cases.app.biz.impl.impl;

import com.gluck.cases.app.biz.impl.AdminRoleService;
import com.gluck.cases.common.utils.enums.BizSerErrorEnum;
import com.gluck.cases.common.utils.utils.AssertUtil;
import com.gluck.cases.core.block.AdminRoleBlock;
import com.gluck.cases.core.modal.assemble.AdminRoleAssemble;
import com.gluck.cases.core.modal.dto.AdminRoleDTO;
import com.gluck.cases.core.modal.req.AdminRoleReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @ClassName AdminRoleServiceImpl
 * @Desc AdminRoleServiceImpl 实现类
 * @Author I am Gluck
 * @Date 2022/5/21 - 11:00 下午
 **/
@Service
public class AdminRoleServiceImpl implements AdminRoleService {

    @Autowired
    private AdminRoleBlock adminRoleBlock;

    @Override
    public void associateRole(AdminRoleReq req) {
        AdminRoleDTO dto = AdminRoleAssemble.AdminRoleReqConvertAdminRoleDTO(req);
        AssertUtil.isFalse(adminRoleBlock.associateRole(dto), BizSerErrorEnum.INSERT_ERROR);
    }

    @Override
    public void removeAssociate(AdminRoleDTO dto) {
        AssertUtil.isFalse(adminRoleBlock.checkAdminRoleExists(dto.getId()), BizSerErrorEnum.DATA_NOT_FOUND);
        AssertUtil.isFalse(adminRoleBlock.removeAssociate(dto), BizSerErrorEnum.ADMIN_ROLE_ASSOCIATE_ERROR);
    }

    @Override
    public void update(AdminRoleDTO dto) {
        AssertUtil.isFalse(adminRoleBlock.checkAdminRoleExists(dto.getId()), BizSerErrorEnum.DATA_NOT_FOUND);
        AssertUtil.isFalse(adminRoleBlock.update(dto), BizSerErrorEnum.ADMIN_ROLE_UPDATE_ERROR);
    }
}
